<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  		<%@include file="/res/include/base-head.jsp"%>
  </head>
  <body>
	
		
<div class="uploadbox">
<form action="${pageContext.request.contextPath}/oss/app/upload2" id="uploaderdata-form" enctype='multipart/form-data' method="post">   
	<input name="folder" type="hidden" value="homemaking/${key}"/>  
	<input id="uploadkey1" name="uploadkey1" type="file"/>
    <div id="uploadnote">支持文件JPG/PNG/BMP格式，最大5mb</div>
    <em id="uploadtxt"></em>
</form>
</div>	   
<script type="text/javascript">
var showId;
$(function(){
	uploader();
})

function uploader() {
	$("#uploaderdata-form").submit(function () {   
        $("#uploaderdata-form").ajaxSubmit({
            type: "post",
            url: contextPath+'/oss/app/upload2',
            dataType:'json',
            beforeSend : beforeSend,
            success: successCallback,
            error: errorback
        });
        return false;
    });
}

function beforeSend(){
	$('#uploadtxt').text('开始上传...');
}

function uploaderStart(id){
	showId = id;
	$("#uploaderdata-form").submit();
}

function successCallback (result) {
	//console.info("---------:"+JSON.stringify(result));
	//---------:{"code":1,"msg":null,"obj":null,"map":{"uploadResults":[{"etag":"9D377B10CE778C4938B3C7E2C63A229A","filePath":"/product/20160818022150_181.jpg","fileSize":777835,"uploadOk":true}]}}
	if (result) {
		if (result.code == 1) {
			$('#uploadtxt').text('上传成功');
			$('#'+showId).html('<p class="img"><img src="'+imgFilePath+result.map.uploadResults[0].filePath+'" alt="" /></p>');
			$('#query-dialog').dialog('close');
		} else {
			$('#uploadtxt').text(result.msg);
		}
	}
}
function errorback () {
	$('#uploadtxt').text('');
	alert("系统繁忙，请稍后再试");
}
</script>
  </body>
</html>
